package com.collabera.labs.sai;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class InvokedActivity extends Activity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
			try {
				tryLogin2();
			} catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
				Log.e("ERRO ! - ", e.getMessage());
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				Log.e("ERRO ! - ", e.getMessage());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				Log.e("ERRO ! - ", e.getMessage());
			}
		setContentView(R.layout.invokedactivity);
	}

	protected void tryLogin2() throws JSONException, ClientProtocolException, IOException {
		JSONObject j = new JSONObject();
		j.put("nome", "joao2");
		j.put("senha", "123456");
		String url = "http://10.0.2.2/Testando/saco.php";
		Map<String, String> kvPairs = new HashMap<String, String>();
		kvPairs.put("usuario", j.toString());
		HttpResponse re = HTTPPoster.doPost(url, kvPairs);
		String temp = EntityUtils.toString(re.getEntity());
		Log.i("main", temp);
		if (temp.compareTo("SUCCESS")==0)
		{
		    Toast.makeText(this, "Sending complete!", Toast.LENGTH_LONG).show();
		    Log.i("main", "aaaaaaaaaaaaa");
		}
	}
}
